import Editor from '../editor';
import { Operation } from './operation'
import RemoveTextOperation from "./remove_text_operation";
import SetSelectionOperation from "./set_selection_operation";

export class InsertTextOperation extends Operation {
    private insertIndex: number
    constructor(private spacers_: string, private insertIndex_: number) {
        super()
        this.insertIndex = insertIndex_
    }

    getIndex() {
        return this.insertIndex;
    }
    getSpacers() {
        return this.spacers_
    }
    setSpacers(spacers: string) {
        return this.spacers_ = spacers

    }
    apply(editor: Editor): void {
        editor.getTextModel()?.insert(this.insertIndex_, this.spacers_)
    }

    inverse(editor: Editor) {
        // editor.getTextModel().remove(this.insertIndex, this.insertIndex + this.spacers_.length);

        throw new Error("Method not implemented.")
    }
    reverse(): Operation[] {
        return [
            new RemoveTextOperation(this.insertIndex, this.insertIndex + this.spacers_.length),
            new SetSelectionOperation({
                anchor: this.insertIndex,
                focus: this.insertIndex
            })
        ];
    }
}

export default InsertTextOperation